//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by yang on 15/11/8.
//  Copyright © 2015年 yang. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabBar = MainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
//        print(tabBar.classForCoder)
        addChildViewControllers()
        //自定义 button的点击事件
        mainTabBar.button.addTarget(self, action: "buttonDidClick", forControlEvents: .TouchUpInside)
    }
    //自定义 button的点击方法
    @objc private func buttonDidClick(){
    let compose = ComposeViewController()
        let nav = UINavigationController(rootViewController: compose)
        presentViewController(nav, animated: true, completion: nil)
    }
    //添加控制器
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
         addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
         addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
         addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    //设置控制器的属性
    private func addChildViewController(vc : UIViewController, title:String, imageName:String) {
        let nav = YQNavigationViewController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named:imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()],forState:UIControlState.Selected)
        addChildViewController(nav)
    }

}
